package com.example.airhockeytextured.program

import android.content.Context
import android.opengl.GLES20
import com.example.airhockeytextured.helper.ShaderHelper
import com.example.airhockeytextured.helper.TexturedHelper
import com.example.airhockeytextured.utils.OpenGLUtils

/**
 * @author Liujianyou
 * @date 2020/8/6
 * @des
 */
open class ShaderProgram constructor(
    context: Context,
    vertexShaderResourceId: String,
    fragmentShaderResourcesId: String
) {
    //Uniform constants
    protected val U_MATRIX = "u_Matrix"
    protected val U_TEXTURE_UNIT = "u_TextureUnit"

    //Attribute constants
    protected val A_POSITION = "a_Position"

    protected val A_COLOR = "a_Color"
    protected val A_TEXTURE_COORDINATES = "a_TextureCoordinates"

    //Shader Program
    protected var program: Int = 0

    init {
        program = ShaderHelper.buildProgram(
            OpenGLUtils.getShaderFromAssets(
                context,
                vertexShaderResourceId
            ), OpenGLUtils.getShaderFromAssets(context, fragmentShaderResourcesId)
        )
    }


    fun usrProgram() {
        //Set the current OpenGL shader program to this program
        GLES20.glUseProgram(program)
    }
}